<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
		<title></title>
		<!--<link href="../js/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">-->
		<link rel="stylesheet" type="text/css" href="../../../js/bootstrap-3.3.7-dist/css/bootstrap.min.css" />
		<!--<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />-->
		<link rel="stylesheet" type="text/css" href="../../../css/footer.css" />
		<link rel="stylesheet" type="text/css" href="../../../css/store_gift.css" />
		<style type="text/css">
			#wrap div#content {
				padding-top: 1.2rem;
			}
		</style>
		<script src="../../../js/flexible.min.js" type="text/javascript" charset="utf-8"></script>
	</head>

	<body style="overflow: auto;">
		<div id="wrap">
			<div id="main">
				<div id="header">
					<a id="headImg" href="../store.html"><img class="headImg" src="../../../images/12.png" /></a>
					<p id="headTitle">礼享商城</p>
				</div>
				<div id="content">
					<div class="search">
						<a></a>
						<input type="text" name="search" id="search" value="" />
					</div>
					<div class="product">
						<div class="product_tabs">
							<a>综合 <img src="../../../images/store/sanjiao1.png" /></a>
							<a>价格 <img src="../../../images/store/sanjiao0.png" /></a>
						</div>
						<ul class="product_list">
							<!--<li>
								<a href="#">
									<img src="../../../images/coalltion/mianbao.jpg"/>
									<p>
										<span>面包面包面包面包面包面包面包</span>
										<label>兑换积分:132.32</label>
									</p>
									
								</a>
							</li>
							<li>
								<a href="#">
									<img src="../../../images/coalltion/mianbao.jpg"/>
									<p>
										<span>面包面包面包面包面包面包面包</span>
										<label>兑换积分:132.32</label>
									</p>
									
								</a>
							</li>
							<li>
								<a href="#">
									<img src="../../../images/coalltion/mianbao.jpg"/>
									<p>
										<span>面包面包面包面包面包面包面包</span>
										<label>兑换积分:132.32</label>
									</p>
									
								</a>
							</li>
							<li>
								<a href="#">
									<img src="../../../images/coalltion/mianbao.jpg"/>
									<p>
										<span>面包面包面包面包面包面包面包</span>
										<label>兑换积分:132.32</label>
									</p>
									
								</a>
							</li>-->
							<div style="clear: both;"></div>
						</ul>
					</div>
				</div>
			</div>
			<ul class="product_down">
				<li>
					<a href="javascript:void(0);" class="fenlei"><img src="../../../images/store/fenlei.png" />分类</a>
				</li>
				<li>
					<a href="javascript:void(0);" class="kefu"><img src="../../../images/store/kefu.png" />客服</a>
				</li>
			</ul>
		</div>
		<div class="leibie">
			<ul>
				<h2>商品分类</h2>
				<li>
					<a>
						全部

					</a>
				</li>
				<!--<li>
					<a href="#">
						水果
					</a>
				</li>
				<li>
					<a href="#">
						海鲜
					</a>
				</li>
				<li>
					<a href="#">
						服装
					</a>
				</li>
				<li>
					<a href="#">
						干果
					</a>
				</li>
				<li>
					<a href="#">
						茶具
					</a>
				</li>-->
			</ul>

		</div>
		<div class="leibie1">
			<ul>

			</ul>
		</div>
	</body>
	<script src="../../../js/jquery-2.2.3.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../../js/bootstrap-3.3.7-dist/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../../js/store_gift.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../../js/handlebars-v2.0.0.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../../js/jquery.cookie.js"></script>
	<script id="table_template1" type="text/x-handlebars-template">
		{{#each this}}
		<li>
			<a href="JavaScript:void(0)" class="{{catId}}">
				{{catName}}
			</a>

		</li>
		{{/each}}
	</script>
	<script id="table_template2" type="text/x-handlebars-template">
		{{#each list}}
		<li>
			<a href="foods_detail.html?sid={{goodsId}}">
				<img src="{{goodsPic}}" />
				<p>
					<span>{{goodsName}}</span>
					<label>兑换积分:{{goodsIntegral}}</label>
				</p>

			</a>
		</li>
		{{/each}}
	</script>
	<script type="text/javascript">
		var tokenReztApp = $.cookie("tokenReztApp");
		if(!tokenReztApp) {
			window.location.href = "../../login/login/login.html";
		}
		$(function() {
			currentyf();
		});

		//用户信息
		var user, role, goodsId;
		//获取当前会员信息
		function currentyf() {
			$.ajax({
				cache: false,
				type: "GET",
				url: "http://47.104.13.109/member-service/auth/current?token=" + tokenReztApp,
				dataType: "JSON",
				async: false,
				error: function(XMLHttpRequest, textStatus, errorThrown) {
					$.removeCookie('tokenReztApp', {
						expires: 7,
						path: '/'
					});
					$.removeCookie("tokenRh", {
						expires: 7,
						path: '/'
					});
					$.removeCookie('memberId', {
						expires: 7,
						path: '/'
					});
					$.removeCookie('roleId', {
						expires: 7,
						path: '/'
					});
					window.location.href = "../../login/login/login.html";
				},
				success: function(data) {
					user = data.loginName;
					role = data.roleList[0].id; //角色
					goodsId = data.id;

				}
			});
		}
		$(function() {

			$.ajax({
				type: "get",
				url: "http://47.104.13.109/product-service/selectcatAll",
				async: true,
				success: function(data) {
					var myTemplate1 = Handlebars.compile($("#table_template1").html());
					$(".leibie>ul").append(myTemplate1(data));
				}
			});
			//搜索
			$(document).on('keydown', function(e) {
				if(e.keyCode == "13") {
					if($('#search').val()) {
						var name = null;
						var num = null;
						if(parseInt($('#search').val())) {
							num = parseInt($('#search').val());
						} else {
							name = $('#search').val();
						}
						$.ajax({
							type: "get",
							url: "http://47.104.13.109/product-service/selectAll",
							async: true,
							data: {
								"pageNum": "1",
								"pageSize": "666",
								"goodsName": name
								//									"goodsStatus":"1"
							},
							success: function(data) {
								var myTemplate4 = Handlebars.compile($("#table_template2").html());
								$('.product_list').html(myTemplate4(data));
								$('.product_list').append("<div style='clear: both;'></div>");
							}
						});
					} else {
						$.ajax({
							type: "get",
							url: "http://47.104.13.109/product-service/selectAll",
							async: true,
							data: {
								"pageNum": "1",
								"pageSize": "666" //
							},
							success: function(data) {
								var myTemplate2 = Handlebars.compile($("#table_template2").html());
								$('.product_list').prepend(myTemplate2(data));
							}
						})
					}
				}
			});

			//排序方式
			var bolTime = true;
			var bolTime1 = true;
			var selectstatus = 1;
			var selectstatus1 = 1;
			$('.product_tabs a:nth-child(1)').on('touchend', function() {
				$('.product_tabs a:nth-child(1) img').attr("src", "../../../images/store/sanjiao1.png");
				$('.product_tabs a:nth-child(2) img').attr("src", "../../../images/store/sanjiao0.png");
				$('.product_tabs a:nth-child(2)').css({
					"color": "black"
				})
				bolTime1 = true;
				if(bolTime) {
					selectstatus = 1;
					bolTime = false;
				} else {
					selectstatus = 2;
					bolTime = true;
					$('.product_tabs a:nth-child(1) img').attr("src", "../../../images/store/sanjiao2.png");
				}
				$(this).css({
					"color": "#e83023"
				});

				$.ajax({
					type: "get",
					url: "http://47.104.13.109/product-service/selectgoodstime",
					async: true,
					data: {
						"pageNum": "1",
						"pageSize": "1000",
						'selectstatus': selectstatus
					},
					success: function(data) {
						var myTemplate5 = Handlebars.compile($("#table_template2").html());
						$('.product_list').html(myTemplate5(data));
						$('.product_list').append("<div style='clear: both;'></div>");
					}
				});
			});
			$('.product_tabs a:nth-child(2)').on('touchend', function() {
				$('.product_tabs a:nth-child(2) img').attr("src", "../../../images/store/sanjiao1.png");
				$('.product_tabs a:nth-child(1) img').attr("src", "../../../images/store/sanjiao0.png");
				$('.product_tabs a:nth-child(1)').css({
					"color": "black"
				})
				bolTime = true;
				if(bolTime1) {
					selectstatus1 = 1;
					bolTime1 = false;
				} else {
					selectstatus1 = 2;
					bolTime1 = true;
					$('.product_tabs a:nth-child(2) img').attr("src", "../../../images/store/sanjiao2.png");
				}
				$(this).css({
					"color": "#e83023"
				});

				$.ajax({
					type: "get",
					url: "http://47.104.13.109/product-service/selectgoodsIntegral",
					async: true,
					data: {
						"pageNum": "1",
						"pageSize": "666",
						'selectstatus': selectstatus1
					},
					success: function(data) {
						var myTemplate5 = Handlebars.compile($("#table_template2").html());
						$('.product_list').html(myTemplate5(data));
						$('.product_list').append("<div style='clear: both;'></div>");
					}
				});
			});

			$.ajax({
				type: "get",
				url: "http://47.104.13.109/product-service/selectAll",
				async: true,
				data: {
					"pageNum": "1",
					"pageSize": "666" //
				},
				success: function(data) {
					console.log(data)
					var myTemplate2 = Handlebars.compile($("#table_template2").html());
					$('.product_list').prepend(myTemplate2(data));
				}
			})

		});
		$(document).on('click', '.leibie>ul>li>a', function() {
			var index = $(this).parent("li").index() * 1 - 1;
			$('.leibie1').show()
			//						console.log(index)
			if(index == 0) {
				$('.leibie1').hide();
				$.ajax({
					type: "get",
					url: "http://47.104.13.109/product-service/selectAll",
					async: true,
					data: {
						"pageNum": "1",
						"pageSize": "666" //
					},
					success: function(data) {
						//									console.log(data);
						var myTemplate2 = Handlebars.compile($("#table_template2").html());
						$('.product_list').prepend(myTemplate2(data));
					}
				})
				$('.leibie').animate({
					"left": "-5rem"
				});
				$('#wrap').animate({
					"left": "0"
				});
				bool = true;
				return
			} else {
				index = $(this).attr('class');
				//							console.log(index)
				this_ = $(this)
			}
			var str = '';
			$(".leibie1 ul").html(str);
			$.ajax({
				type: "get",
				url: "http://47.104.13.109/product-service/selectchildren",
				async: false,
				data: {
					"pageNum": "1",
					"pageSize": "666",
					catId: index
				},
				success: function(res1) {
					console.log(res1.list);
					if(res1.list == '') {
						$.ajax({
							type: "post",
							url: "http://47.104.13.109/product-service/selectbycatids?pageNum=1&pageSize=100",
							async: false,
							contentType: "application/json",
							data: index,
							success: function(res3) {
								console.log(res3)
								$.each(res3.list, function(idx, item) {
									var myTemplate3 = Handlebars.compile($("#table_template2").html());
									$('.product_list').html(myTemplate3(res3));
									$('.product_list').append("<div style='clear: both;'></div>");
								});
								$('.leibie1').hide();
								$('.leibie').animate({
									"left": "-5rem"
								});
								$('#wrap').animate({
									"left": "0"
								});
								bool = true;
							}
						});
						return
					}
					str = '<h2>' + this_.html() + ' <a class="return" href="JavaScript:void(0)" style="font-size:15px; color:white;float:right;">返回 </a></h2>'
					$.each(res1.list, function(idx1, item1) {
						str += '<li><a href="javascript:void(0);" data-a="' + item1.catId + '">' + item1.catName + '</a></li>'

					});
					$(".leibie1 ul").html(str);
					//								console.log(str)
					$(".leibie1").show();
				}
			});
		});
		//分类导航
		$(document).on('click', '.leibie1>ul>li>a', function() {
			var index = $(this).attr('data-a');
			console.log(index)
			$('.product_list').html(' ');
			$.ajax({
				type: "post",
				url: "http://47.104.13.109/product-service/selectbycatids?pageNum=1&pageSize=100",
				async: false,
				contentType: "application/json",
				data: index,
				success: function(res) {
					console.log(res)
					$.each(res.list, function(idx, item) {
						var myTemplate3 = Handlebars.compile($("#table_template2").html());
						$('.product_list').html(myTemplate3(res));
						$('.product_list').append("<div style='clear: both;'></div>");
					});
					$('.leibie1').hide();
					$('.leibie').animate({
						"left": "-5rem"
					});
					$('#wrap').animate({
						"left": "0"
					});
					bool = true;
				}
			});

		})
		$(document).on("click", ".return", function() {
			$('.leibie1').hide();
		})
	</script>

</html>